package com.ja.openchat.ui.chat.redpacket;

import android.os.Bundle;

import androidx.annotation.IntRange;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.google.gson.JsonObject;
import com.ja.openchat.ui.me.AbsRecordFragment;
import com.zy.openchat.core.manager.TelegramManager;
import com.zy.openchat.core.manager.TgResultBlock;
import com.zy.openchat.core.model.redpacket.RedPacketInfo;

import java.util.List;
import java.util.Map;

public class RedPacketRecordFragment extends AbsRecordFragment<RedPacketInfo> {

    public static RedPacketRecordFragment newInstance(@IntRange(from = 0,to = 2) int recordType){
        RedPacketRecordFragment fragment = new RedPacketRecordFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("recordType",recordType);
        fragment.setArguments(bundle);
        return fragment;
    }

    private int recordType;

//    @Override
//    protected void initDataAndEvent(Bundle savedInstanceState) {
//        if(getArguments()!=null){
//            recordType = getArguments().getInt("recordType");
//        }
//        super.initDataAndEvent(savedInstanceState);
//    }

    @Override
    protected BaseQuickAdapter<RedPacketInfo, BaseViewHolder> newIntanceAdapter() {
        return new RedPacketRecordAdapter(recordType==2);
    }

    @Override
    protected void requestData(int page) {
        TelegramManager.getTelegramManager().queryRedHistoryCall(getContext(),recordType==1?2:1, PAGE_COUNT, currentPage, new TgResultBlock<List<RedPacketInfo>>() {
            @Override
            public void onResult(Map<String, Object> request, JsonObject response, List<RedPacketInfo> obj) {
                finishRefreshAndLoad(page,obj);

            }

            @Override
            public void onTimeout(Map<String, Object> request) {
                finishRefreshAndLoad(page,null);
            }
        });
    }
}
